<template>
  <div class="login-container">
    <el-form v-if="type=='forget'" ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
      <el-row>
      <div class="title-container">
        <h3 class="title">忘记密码</h3>
      </div>

      <el-form-item prop="username">
        <el-input
          ref="username"
          v-model="loginForm.phone"
          placeholder="请输入手机号"
          maxlength="11"
          name="username"
          type="text"
          tabindex="1"
          auto-complete="on"
        />
      </el-form-item>
        <el-row :gutter="24">
        <el-col :span="17">
          <el-form-item prop="password">
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.phoneCode"
              placeholder="输入验证码"
              name="password"
              tabindex="2"
              auto-complete="on"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-button @click="getCode">获取验证码</el-button>
        </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="17">
            <el-form-item prop="password">
              <el-input
                :key="passwordType"
                ref="password"
                v-model="loginForm.phoneCode"
                placeholder="输入图形验证码"
                name="password"
                tabindex="2"
                auto-complete="on"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button @click="getCode">获取验证码</el-button>
          </el-col>
        </el-row>
 <div style="text-align: center">

         <el-button :loading="loading" type="primary" style="width:50%; margin-bottom:30px;" @click="next">下一步</el-button>

 </div>

        </el-row>
    </el-form>
    <el-form v-else ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left" label-width="100px">
      <el-row>
        <div class="title-container">
          <h3 class="title">修改密码</h3>
        </div>

        <el-form-item prop="username" label="新密码">
          <el-input
            ref="username"
            v-model="loginForm.phone"
            placeholder="6 - 16位密码，区分大小写"
            name="username"
            type="text"


            auto-complete="on"
          />
        </el-form-item>

            <el-form-item prop="password" label="确认新密码">
              <el-input
                :key="passwordType"
                ref="password"
                v-model="loginForm.phoneCode"
                placeholder="请再次输入新密码"
                name="password"
                tabindex="2"
                auto-complete="on"
              />
            </el-form-item>
        <div style="text-align: right;margin-bottom: 10px">

        <router-link style="color: deepskyblue" to="/login">去登陆</router-link>

        </div>

        <div style="text-align: center">

          <el-button :loading="loading" type="primary" style="width:50%; margin-bottom:30px;" @click="handleLogin">下一步</el-button>

        </div>

      </el-row>
    </el-form>
  </div>
</template>

<script>
import { validUsername } from '@/utils/validate'

export default {
  name: 'Login',
  data() {

    return {
      loginForm: {
        phone: '',
        phoneCode: ''
      },
      loginRules: {

      },
      loading: false,
      passwordType: 'password',
      redirect: undefined,
      checked: true,
      type:'forget'
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    next(){
      this.type = 'chongzhi'
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then(() => {
            this.$router.push({ path: '/' })
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        } else {
          // console.log('error submit!!')
          return false
        }
      })
    },
    //获取验证码
    getCode(){

    },
    //忘记密码
    forgetPassword(){
      // console.log('123123');
      this.$router.push({path:'/forgetPassword'})
    },
    qwe(){
      this.$router.push({path:'/index'})
    }
  }
}
</script>



<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 60px 35px 0;
    margin: 0 auto;
    overflow: hidden;
 background-color: white;
    margin-top: 160px;
  }





  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: black;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  //密码
  .passwordStyle{
    display: flex;
    justify-content: space-between;
    color: white;
    margin-bottom: 30px;
  }
  .el-checkbox__label {
    display: inline-block;
    padding-left: 10px;
    line-height: 19px;
    font-size: 14px;
    color: white;
  }
}
</style>
